#!/bin/bash

RATE_LIMIT="2m:1m"

if [ $# -lt 2 ]; then
   echo "Usage: $0 index-URL store-directory"
   exit 1
fi

index="$1" # e.g. https://kat.cr/movies/
store="$2"

urls="$(lynx "$index" -dump -listonly | grep magnet: | awk 'BEGIN {ORS=" "} {print "\""$2"\""}')"
exec lftp -e "set limit-total-rate $RATE_LIMIT; set cmd:interactive yes; \
torrent -O \"$store\" --only-new $urls &"
